import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import Home from '../views/Home.vue'
import Article from '../views/Article.vue'
import Cate from '../views/Cate.vue'

Vue.use(VueRouter)

const routes = [
	{
		path: '/login',
		component: Login
	},
	{
		path: '/',
		component: Home,
		children:[
			{
				path: '/article',
				component: Article,
				name : Article
			},
			{
				path: '/cate',
				component: Cate,
				name : Cate
			}
		]
	},
	
]

const router = new VueRouter({
  routes
})

router.beforeEach((to,from,next)=>{
	if (to.path == '/login') {
		next()
	}
	
	if(!window.sessionStorage.getItem('token') || window.sessionStorage.getItem('token') == '' || window.sessionStorage.getItem('token') == null || window.sessionStorage.getItem('token') == undefined){
			next('/login')
	}
	next()
})

export default router
